package com.person.leetcode.editor.cn;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
  * 49.字母异位词分组
  * 2022-11-02 17:07:46
**/
public class Sequence_0049_GroupAnagrams {
    public static void main(String[] args) {
        Solution solution = new Sequence_0049_GroupAnagrams().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> strMap = new HashMap<>();
        for (int i = 0; i < strs.length; i++) {
            String str = strs[i];
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            List<String> strList = strMap.getOrDefault(key, new ArrayList());
            strList.add(str);
            strMap.put(key,strList);
        }
        return new ArrayList<List<String>>(strMap.values());
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}